package com.example.weight.navigation;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.weight.R;
import com.example.weight.greenSeasons.deodorization.D4Activity;
import com.example.weight.greenSeasons.waterDeal.DeodorizationTable;
import com.example.weight.greenSeasons.waterDeal.RepairTable;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import java.util.ArrayList;
import java.util.Arrays;

public class SijiqingCenterNavActivity extends AppCompatActivity {

    private Button solidLiquidSep, flocculation, compost, waterDeal,
            deodorization, systemMaintain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sijiqing_center_nav);

        Intent previousIntent = getIntent();
        final String name = previousIntent.getStringExtra("name");
        final String factory = previousIntent.getStringExtra("factory");
        Log.d("sijiqingnavi", factory);

        String permissionLevel = previousIntent.getStringExtra("permissionLevel");

        TitleBar titleBar = findViewById(R.id.sijiqing_center_nav_titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {}

            @Override
            public void onRightClick(View v) {}
        });

//        weight = findViewById(R.id.sijiqing_weight_nav);
//        weight.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(SijiqingCenterNavActivity.this, SijiqingWeightNavActivity.class);
//                intent.putExtra("name", name);
//                startActivity(intent);
//            }
//        });

        solidLiquidSep = findViewById(R.id.sijiqing_solid_liquid_sep_nav);
        solidLiquidSep.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SijiqingCenterNavActivity.this, SijiqingSolidLiquidSepNavActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);

                //intent.putExtra("fName", "solid_liquid");
                startActivity(intent);
            }
        });

        flocculation = findViewById(R.id.sijiqing_flocculation_nav);
        flocculation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SijiqingCenterNavActivity.this, SijiqingFlocculationNavActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        compost = findViewById(R.id.sijiqing_compost_nav);
        compost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SijiqingCenterNavActivity.this, SijiqingCompostNavActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                Log.d("sijiqingnavicompost", factory);

                startActivity(intent);
            }
        });

        waterDeal = findViewById(R.id.sijiqing_water_deal_nav);
        waterDeal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SijiqingCenterNavActivity.this, SijiqingWaterDealNavActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        deodorization = findViewById(R.id.sijiqing_deodorization_nav);
        deodorization.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SijiqingCenterNavActivity.this, SijiqingDeodorizationNavActivity.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        systemMaintain = findViewById(R.id.sijiqing_system_maintain_nav);
        systemMaintain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SijiqingCenterNavActivity.this, RepairTable.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        initNavEnable(permissionLevel);
    }

    private void initNavEnable(String permissionLevel) {
        if (permissionLevel.equals("0"))
            return;
//        weight.setEnabled(false);
        solidLiquidSep.setEnabled(false);
        flocculation.setEnabled(false);
        compost.setEnabled(false);
        waterDeal.setEnabled(false);
        deodorization.setEnabled(false);
        systemMaintain.setEnabled(false);
        if (permissionLevel.contains("固液分离"))
            solidLiquidSep.setEnabled(true);
        if (permissionLevel.contains("絮凝"))
            flocculation.setEnabled(true);
        if (permissionLevel.contains("堆肥"))
            compost.setEnabled(true);
        if (permissionLevel.contains("水处理"))
            waterDeal.setEnabled(true);
        if (permissionLevel.contains("除臭"))
            deodorization.setEnabled(true);
        if (permissionLevel.contains("技术维护"))
            systemMaintain.setEnabled(true);
    }
}
